/**
 * JAVACC DEMO 1.0
 */
package com.apache.client;

import com.apache.api.vo.ResultEntity;
import com.apache.api.vo.ResultMsg;
import com.apache.tools.ConfigUtil;
import com.apache.tools.StrUtil;

import java.util.Map;

/**
 * description:  信息收藏客户端
 *
 */
public class InfoFavoriteCoreClient {

    private static InfoFavoriteCoreClient instance;

    private static final String serviceName = "infoService";

    private InfoFavoriteCoreClient() {
    }

    public static InfoFavoriteCoreClient getInstance() {
        if (null == instance) {
            instance = new InfoFavoriteCoreClient();
        }
        return (instance);
    }

    /**
     * description:  保存信息
     */
    public ResultMsg saveInfo(Map map) {
        ResultMsg msg = new ResultMsg("F", "操作失败");
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "insertInfo", map);
        if ("true".equals(entity.getResult()) && StrUtil
                .isNotNull(String.valueOf(entity.getEntity()))) {
            msg = new ResultMsg("T", "保存成功");
        } else {
            msg.setMsg(entity.getMessage());
        }
        return msg;
    }

    /**
     * description:  修改信息
     */
    public ResultMsg updateInfo(Map map) {
        ResultMsg msg = new ResultMsg("F", "操作失败");
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "updateInfo", map);
        if ("true".equals(entity.getResult()) && StrUtil
                .isNotNull(String.valueOf(entity.getEntity()))) {
            msg = new ResultMsg("T", "操作成功");
        } else {
            msg.setMsg(entity.getMessage());
        }
        return msg;
    }

    /**
     * description:  删除信息
     */
    public ResultMsg deleteInfo(Map map) {
        ResultMsg msg = new ResultMsg("F", "操作失败");
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "deleteInfo", map);
        if ("true".equals(entity.getResult()) && StrUtil
                .isNotNull(String.valueOf(entity.getEntity()))) {
            msg = new ResultMsg("T", "操作成功");
        } else {
            msg.setMsg(entity.getMessage());
        }
        return msg;
    }

    /**
     * description:  查询信息列表
     */
    public Object selectInfo(Map map) {
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "selectInfo", map);
        if ("true".equals(entity.getResult()) && null != entity.getEntity()) {
            return entity.getEntity();
        }
        return null;
    }

    /**
     * description:  查询单个信息
     */
    public Object selectSingle(Map map) {
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "selectSingle", map);
        if ("true".equals(entity.getResult()) && null != entity.getEntity()) {
            return entity.getEntity();
        }
        return null;
    }

    /**
     * description:  查询单个信息
     */
    public long countInfo(Map map) {
        map.put("sysPass", ConfigUtil.getInstance().interfacePass());
        ResultEntity entity = UctProtoclClient.getInstance()
                .doInfoService(serviceName, "countInfo", map);
        if ("true".equals(entity.getResult()) && StrUtil
                .isNotNull(String.valueOf(entity.getEntity()))) {
            return Long.valueOf(String.valueOf(entity.getEntity()));
        }
        return 0;
    }

}
